package org.thanos.baseline.utils;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTimeFormatterUtil {

    public static final String YYYY = "yyyy";
    public static final String YYYYMM = "yyyyMM";
    public static final String YYYYMMDD = "yyyyMMdd";
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String YYYY_MM_EN = "yyyy/MM";
    public static final String YYYY_MM_DD_EN = "yyyy/MM/dd";
    public static final String YYYY_MM_DD_HH_MM_EN = "yyyy/MM/dd HH:mm";
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS_FMT = DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS).withZone(ZoneId.systemDefault());
    public static final DateTimeFormatter YYYY_MM_DD_FMT = DateTimeFormatter.ofPattern(YYYY_MM_DD).withZone(ZoneId.systemDefault());
    public static final DateTimeFormatter YYYYMMDDHHMMSS_FMT = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").withZone(ZoneId.systemDefault());

    private DateTimeFormatterUtil() {
    }

    public static boolean isValidDate(String time) {
        try {
            LocalDate localDate = LocalDate.parse(time, YYYY_MM_DD_FMT);
            Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
